Skip to content

ListInput

Base classes

Name Children Inherits
LineEdit
prettyqt.widgets.lineedit
One-line text editor.

⋔ Inheritance diagram

graph TD
  1189340652["custom_widgets.ListInput"]
  1980365965["widgets.LineEdit"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  1326755038["QtWidgets.QLineEdit"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  1980365965 --> 1189340652
  829357528 --> 1980365965
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  1326755038 --> 1980365965
  3620195106 --> 1326755038
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: LineEdit

Source code in prettyqt/custom_widgets/editors/listinput.py
class ListInput(widgets.LineEdit):
    value_changed = core.Signal(list)

    def __init__(
        self,
        value: list[float] | str = "",
        typ: type = int,
        allow_single: bool = False,
        object_name: str = "list_input",
        **kwargs,
    ):
        super().__init__(object_name=object_name, **kwargs)
        match typ:
            case builtins.int:
                self.set_validator("int_list", allow_single=allow_single)
            case builtins.float:
                self.set_validator("float_list", allow_single=allow_single)
            case _:
                msg = f"Invalid type {typ}"
                raise ValueError(msg)
        self.set_value(value)

    def get_value(self) -> list[float | int]:  # type: ignore[override]
        # TODO: is this best place to deal with exception?
        try:
            return helpers.string_to_num_array(self.text())
        except ValueError:
            return []

    def set_value(self, value: list[float] | str):
        if isinstance(value, list):
            value = str(value)[1:-1].replace(" ", "")
        self.set_text(value)

:fa-brands-github: Show source on GitHub